import Vue from 'vue'

// import Cookies from 'js-cookie'

import 'normalize.css/normalize.css' // a modern alternative to CSS resets

import Element from 'element-ui'
import './styles/element-variables.scss'
import zhLang from 'element-ui/lib/locale/lang/zh-CN'// 如果使用中文语言包请默认支持，无需额外引入，请删除该依赖
import idLang from 'element-ui/lib/locale/lang/id'// 如果使用中文语言包请默认支持，无需额外引入，请删除该依赖

import VueI18n from 'vue-i18n'
import id_ID from './assets/i18n/id-ID'
import zh_CN from './assets/i18n/zh-CN'
// import ElementLocale from 'element-ui/lib/locale'

import '@/styles/index.scss' // global css

import App from './App'
import store from './store'
import router from './router'

import './icons' // icon
import './permission' // permission control
import './utils/error-log' // error log

import * as filters from './filters'
import { localRead } from './utils/auth' // global filters

/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online ! ! !
 */
// if (process.env.NODE_ENV === 'production') {
//   const { mockXHR } = require('../mock')
//   mockXHR()
// }
Vue.use(Element, {
  i18n: (key, value) => i18n.t(key, value)
})
Vue.use(VueI18n)
const navLang = navigator.language
const str = localRead('local')
console.log(str)
const localLang = str ? (str === 'zh-CN') ? str : 'id-ID' : ((navLang === 'zh-CN') ? navLang : 'id-ID')
Vue.config.lang = localLang

// vue-i18n 6.x+写法
Vue.locale = () => {}
const messages = {
  'zh-CN': Object.assign(zhLang, zh_CN),
  'id-ID': Object.assign(idLang, id_ID)
}
const i18n = new VueI18n({
  locale: navLang, // set locale
  messages // set locale messages
})

// register global utility filters
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})

Vue.config.productionTip = false

new Vue({
  el: '#app',
  router,
  store,
  i18n,
  render: h => h(App)
})
